﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework.Graphics;
using Najak;

namespace Falon.Items
{
	public enum DamageType
	{
		Flesh,
		Blunt,
		Sharp,
		Piercing,
		Siege
	}

	public class Weapon : Item, IProjectileOwner
	{
		public float Damage;
		public float Range;
		public float AttackRate;
		public DamageType DamageType;
		public Projectile Projectile;

		private Weapon()
		{
		}

		public Weapon(string textureName, string name, float damage, float attackRate, float range, Projectile projectile)
		{
			TextureName = textureName;
			Damage = damage;
			AttackRate = attackRate;
			Range = range;
			Name = name;
			Projectile = projectile;
		}

		public void Update(float timeDelta)
		{
		}

		void IProjectileOwner.OnProjectile_EntityImpact(Projectile projectile, Entity entity)
		{
			OnProjectile_UnitImpact(projectile, entity);
		}
		virtual protected void OnProjectile_UnitImpact(Projectile projectile, Entity entity)
		{
			int damage = (int)Owner.Weapon.Damage - (int)Owner.Armor.Defense;
			if (damage >= 0)
				entity.TakeDamage(damage, Owner);
			OnProjectileTerminated(projectile);
		}

		void IProjectileOwner.OnProjectile_TileImpact(Projectile projectile, Tile tile, Coordinate coord)
		{
			OnProjectile_TileImpact(projectile, tile, coord);
		}
		virtual protected void OnProjectile_TileImpact(Projectile projectile, Tile tile, Coordinate coord)
		{
			OnProjectileTerminated(projectile);
		}

		void IProjectileOwner.OnProjectile_Expired(Projectile projectile, bool hitGround)
		{
			OnProjectile_Expired(projectile, hitGround);
		}
		virtual protected void OnProjectile_Expired(Projectile projectile, bool hitGround)
		{
			OnProjectileTerminated(projectile);
		}

		virtual protected void OnProjectileTerminated(Projectile projectile)
		{
			projectile.Scene.Projectiles.Remove(projectile);
		}

	}
}
